package tr.edu.metu.is.mega.server.business;

import java.sql.Timestamp;

import tr.edu.metu.is.mega.common.dto.ActivityDTO;
import tr.edu.metu.is.mega.common.dto.ActivityType;
import tr.edu.metu.is.mega.server.core.AbstractDTOHelper;
import tr.edu.metu.is.mega.server.entity.Activity;

/**
 * Helper class to convert between DTO and entity.
 */
public class ActivityDTOHelper extends AbstractDTOHelper<ActivityDTO, Activity> {

    /**
     * Default constructor.
     */
    public ActivityDTOHelper() {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ActivityDTO convertToDTO(Activity from) {
        ActivityDTO to = new ActivityDTO();
        to.setPkid(from.getPkid());
        to.setAlertTime(from.getAlerttime());
        to.setDescription(from.getDescription());
        to.setDueDate(from.getDuedate());
        to.setType(ActivityType.findByCode(from.getSubmissiontype()));
        return to;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void convertToEntity(ActivityDTO dto, Activity activity) {
        activity.setPkid(dto.getPkid());
        activity.setAlerttime(new Timestamp(dto.getAlertTime().getTime()));
        activity.setDescription(dto.getDescription());
        activity.setDuedate(new Timestamp(dto.getDueDate().getTime()));
        activity.setSubmissiontype(dto.getType().getCode());
    }

}
